#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 110, INF = 1e8;
int e[N][N];
int f[N][N];
int n, m;
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            f[i][j] = e[i][j] = INF;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        f[i][i] = e[i][i] = 0;
    }
    for (int i = 1; i <= m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        e[a][b] = e[b][a] = f[a][b] = f[b][a] = min(e[a][b], c);
    }
    int ret = INF;
    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i < k; i++)
        {
            for (int j = i + 1; j < k; j++)
            {
                ret = min(ret, f[i][j] + e[i][k] + e[k][j]);
            }
        }
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
            }
        }
    }
    if (ret == INF)
    {
        cout << "No solution." << endl;
    }
    else
    {
        cout << ret << endl;
    }
    return 0;
}